package frame;

import service.UserServise;
import service.impl.UserServiseImpl;
import util.AtmUtil;
import util.GuiImg;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Deposit extends JPanel implements ActionListener {
    /**
     * 存款
     */
    private Icon atmIcon7 = GuiImg.getIcon("/imgs/buttonSure.jpg");
    private JButton btnlogin7 = new JButton(atmIcon7);
    private Atm frame;
    private JTextField textField1;
    private UserServise userServise=new UserServiseImpl();

    public Deposit(Atm frame) {
        this.frame = frame;
        this.setLayout(null);
        //单行输入框
        textField1 = new JTextField();
        textField1.setBounds(250, 200, 250, 30);
        this.add(textField1);
        //确认按钮
        this.setOpaque(false);
        btnlogin7.setBounds(330, 300, 100, 40);
        this.add(btnlogin7);
        btnlogin7.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == btnlogin7){
           userServise.depositMoney(frame.getLoginuser().getId(),Double.parseDouble(textField1.getText()));
            JOptionPane.showMessageDialog(this, "存款成功");
            frame.switchPanel("菜单");
        }
    }

    public JTextField getTextField1() {
        return textField1;
    }

    public void setTextField1(JTextField textField1) {
        this.textField1 = textField1;
    }
}

